package com.panda.admin.login.auth.detailsVo;

import com.panda.admin.login.entity.SystemUser;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

/**
 * author: tcy
 * createDate: 2022/11/9
 * description:系统管理用户认证信息
 */
@Data
public class SysUserDetails implements UserDetails, Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;
    private String nickName;

    /**
     * UserDetails默认字段
     */
    private String username;
    private String password;
    private String openId;
    private Long roleId;
    private String mobile;
    private String email;
    private String iconUrl;
    private Collection<SimpleGrantedAuthority> authorities;

    public SysUserDetails(SystemUser user){
        this.setId(user.getId());
        this.setNickName(user.getNickname());
        this.setUsername(user.getAccount());
        this.setPassword(user.getPassword());
        this.setOpenId(user.getOpenId());
        this.setRoleId(user.getRoleId());
        this.setMobile(user.getMobile());
        this.setEmail(user.getEmail());
        this.setIconUrl(user.getIconUrl());
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    //获取密码
    @Override
    public String getPassword() {
        return this.password;
    }

    //获取用户名
    @Override
    public String getUsername() {
        return this.username;
    }

    //账号是否可用
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    //账号是否锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    //凭证是否过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    //用户是否正常
    @Override
    public boolean isEnabled() {
        return true;
    }
}
